<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-dialog
        title="请选择打印模板"
        :visible.sync="crud.printConfig.pringDialog"
        width="30%"
        v-dialogDrag
      >
        <jPrintConfig groupId="wareCheck"
                      v-if="crud.printConfig.pringDialog"
                      @getPrintId="crud.detailedPrint"
                      :isPreview="crud.printConfig.isPreview"
        ></jPrintConfig>
      </el-dialog>
      <el-form size="small"
               label-width="100px"
               :rules="rules"
               ref="form"
               :model="crud.order"
               :disabled="crud.order.checkStatus==='PASS'">
        <el-row :gutter="10">
          <!--侧边部门数据-->
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="单据编码">
              <el-input placeholder="系统自动生成" disabled v-model="crud.order.code"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="日期">
              <el-date-picker
                style="width: 100%"
                type="date"
                disabled
                v-model="crud.order.busDate"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="盘点状态">
              <el-select v-model="crud.order.isCheck" disabled style="width:100%">
                <el-option
                  v-for="item in dict.common_yes_or_no"
                  :key="item.id"
                  :label="item.label"
                  :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="仓库" prop="warehouseId">
              <zSelect :value.sync="crud.order.warehouseId" :showName="crud.order.warehouseName" :laber="crud.order.warehouseName"   url="api/dropDown/basWarehouseList" />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="盘点人员" prop="userId">
              <zSelect :value.sync="crud.order.userId" :showName="crud.order.userName"  :laber="crud.order.userName" url="api/dropDown/sysUserList" :params="{businessAttr:'3',isContact:'1,2'}"
                       style="width:  100%"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="第几次盘点" prop="userId">
              <el-input-number style="width: 100%" type="number" v-model="crud.order.checkNum"/>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
            <el-form-item label="备注">
              <el-input v-model="crud.order.remark"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <!--批量新增弹窗-->
    <el-dialog :close-on-click-modal="false" title="商品新增"
               :visible.sync="showAddBatchDialog" append-to-body width="100vw">
      <add-batch v-if="showAddBatchDialog" :showAddBatchDialog.sync="showAddBatchDialog" :list="detailList"
                 :params="{customerId:crud.order.customerId,type:crud.order.type==1?'SALE':'SALE_RETURN',
                 warehouseId:crud.order.warehouseId
                 }"
                 :saleType="crud.order.saleType"
                 :type="crud.order.type"
                 @change="afterChangeGoods"></add-batch>
    </el-dialog>
      <!--头部功能按钮-->
      <div class="head-container">
        <crud-operation :permission="permission">
          <el-button
            slot="left"
            class="filter-item"
            size="mini"
            :disabled="crud.order.orderStatus==='PASS'"
            type="primary"
            @click="toAdd()"
          >
            新增
          </el-button>
          <el-button
          slot="right"
          class="filter-item"
          size="mini"
          type="primary"
          :disabled=" crud.order.orderStatus==='PASS'"
          @click="toAddList"
        >
          批量新增
        </el-button>
          <el-button
            slot="right"
            class="filter-item"
            size="mini"
            type="primary"
            icon="el-icon-plus"
            @click="submit"
          >
            保存
          </el-button>
          <el-button
            slot="right"
            class="filter-item"
            size="mini"
            type="success"
            icon="el-icon-refresh-right"
            :disabled="$route.params.id=='null'"
            :loading="crud.passLoading"
            @click="crud.doDetailPassOrReject('PASS')"
            v-permission="permission.pass"
          >
            审核
          </el-button>
          <el-button
            slot="right"
            class="filter-item"
            size="mini"
            type="info"
            icon="el-icon-refresh-left"
            :loading="crud.rejectLoading"
            :disabled="$route.params.id=='null'"
            @click="crud.doDetailPassOrReject('REJECT')"
            v-permission="permission.reject"
          >
            反审
          </el-button>
          <el-button
            slot="right"
            class="filter-item"
            size="mini"
            type="success"
            icon="el-icon-check"
            @click="setCheck('checkFinish')"
            v-permission="permission.checkFinish"
          >
            盘点完成
          </el-button>
          <el-button
            slot="right"
            class="filter-item"
            size="mini"
            type="warning"
            icon="el-icon-bicycle"
            @click="setCheck('checkAppend')"
            v-permission="permission.checkAppend"
          >
            追加盘点
          </el-button>
          <el-button
            slot="right"
            class="filter-item"
            size="mini"
            type="warning"
            icon="el-icon-edit-outline"
            @click="setCheck('addOrSub')"
            v-permission="permission.addOrSub"
          >
            盈亏调整
          </el-button>
          <el-button
            slot="left"
            class="filter-item"
            size="mini"
            type="success"
            @click="goodsMerge"
            :disabled="crud.order.orderStatus!=='SAVE'"
            v-permission="permission.goodsMerge"
          >
            商品合并
          </el-button>
          <el-button
            slot="right"
            :loading="crud.downloadLoading"
            class="filter-item"
            size="mini"
            type="warning"
            @click="crud.preView"
            :disabled="$route.params.id == 'add'"
          >打印</el-button>
          <el-button
            slot="right"
            :loading="crud.downloadLoading"
            class="filter-item"
            size="mini"
            type="warning"
            @click="crud.preView1"
            :disabled="$route.params.id == 'add'"
          >打印预览</el-button>
        </crud-operation>
      </div>
      <!--表格渲染-->
      <el-table ref="table"
                v-loading="crud.loading"
                :row-class-name="crud.tableRowClassName"
                :data="crud.data"
                size="small" style="width: 100%;"
                sortable="custom"
                border @row-click="crud.selectRow" highlight-current-row="highlight-current-row"
                @sort-change="crud.sortChange"
                @selection-change="crud.selectionChangeHandler"
                @row-dblclick="switchRowIndex">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" label="序号" type="index" width="50"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCode')" prop="goodsCode" label="商品编码"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsName')" prop="goodsName" label="商品名称" width="360">
          <template slot="header">
            <span style="color: red">*</span>商品名称
          </template>
          <template slot-scope="scope">
            <span v-if="scope.$index !== rowIndex">{{ scope.row.goodsName }}</span>
            <jtg-select-plus v-else ref="productRef"
                             v-model="scope.row.goodsId"
                             typeName="STOCK"
                             :params="{warehouseId:crud.order.warehouseId}"
                             :initValue="scope.row.goodsName"
                             @remoteMethod="getValue($event,scope.$index)"
                             @input="getInput($event,name,scope.$index)"
                             @change="crud.productChange($event,scope)"
                             url="productList"/>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('barcode')" prop="barcode" label="条形码"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('helpSign')" prop="helpSign" label="助记符"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('model')" prop="model" label="规格型号"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('mainUnitName')" prop="mainUnitName" label="单位"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsBrandName')" prop="goodsBrandName" label="品牌"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsTypeName')" prop="goodsTypeName" label="商品分类"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('storehouseName')" prop="storehouseName" label="货位"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('existNum')" prop="existNum" label="现存量"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('existBoxNum')" prop="existBoxNum" label="现存箱数"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('existMainNum')" prop="existMainNum" label="现存零数"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('paperNum')" prop="paperNum" label="账面数量">
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('paperBoxNum')" prop="paperBoxNum" label="账面箱数" />

        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('paperMainNum')" prop="paperMainNum" label="账面零数"/>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCount')" prop="goodsCount" label="实际数量"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="实际箱数"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('paperMainNum')" prop="paperMainNum" label="实际零数"/>-->

        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickNum')" prop="pickNum" label="拣货数量"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCount')" prop="goodsCount" label="实际数量" width="90" sortable>
          <template slot-scope="scope">
            <span  v-if="scope.$index !== rowIndex">{{ scope.row.goodsCount  }}</span>
            <el-input v-else
                      oninput="value=value.replace(/[^\d^\.]/g,'')"
                      @change="changeNum(scope.row,'count')"
                      v-model.lazy="scope.row.goodsCount "/>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxNum')"  prop="boxNum" label="实际箱数" width="90" sortable>
          <template slot-scope="scope">
            <span  v-if="scope.$index !== rowIndex">{{ scope.row.boxNum }}</span>
            <el-input v-else
                      @change="changeNum(scope.row,'box')"
                      oninput="value=value.replace(/[^\d^\.]/g,'')"
                      v-model.lazy="scope.row.boxNum"/>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('mainNum')" prop="mainNum" label="实际零数" width="90" sortable>
          <template slot-scope="scope">
            <span v-if="scope.$index !== rowIndex">{{ scope.row.mainNum }}</span>
            <el-input v-else
                      oninput="value=value.replace(/[^\d^\.]/g,'')"
                      @change="changeNum(scope.row,'main')"
                      v-model.lazy="scope.row.mainNum"/>
          </template>
        </el-table-column>
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('productCount')" prop="productCount" label="盘点量" width="90" sortable>-->
<!--          <template slot-scope="scope">-->
<!--            <span v-if="!scope.row.isSelected">{{ scope.row.productCount }}</span>-->
<!--            <el-input v-if="scope.row.isSelected"-->
<!--                      oninput="value=value.replace(/[^\d^\.]/g,'')"-->
<!--                      @input.native="crud.inuptCount(scope,'productCount','STOCK')"-->
<!--                      v-model.lazy="scope.row.productCount"/>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="盘点箱数" width="120" sortable/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('occupyNum')" prop="occupyNum" label="占用量"/>-->
<!--        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('occupyBox')" prop="occupyBox" label="占用箱数"/>-->
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('profitLossNum')" prop="profitLossNum" label="盈亏数量">
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('profitLossBoxNum')" prop="profitLossBoxNum" label="盈亏箱数"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('profitLossMainNum')" prop="profitLossMainNum" label="盈亏零数"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('producedDate')" prop="producedDate" label="生产日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.producedDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('deadlineDate')" prop="deadlineDate" label="截止日期" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.deadlineDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注"/>
        <el-table-column :render-header="crud.renderHeader"  label="操作" fixed="right" width="200px" align="center">
          <template slot-scope="scope">
<!--              <el-button-->
<!--                type="primary"-->
<!--                icon="el-icon-plus"-->
<!--                circle-->
<!--                v-if="(crud.data.length-1)==scope.$index"-->
<!--                :disabled="crud.order.orderStatus==='PASS'"-->
<!--                @click="crud.addRow(scope.$index)"></el-button>-->
            <el-button
              slot="reference" class="el-icon-delete opration_icon_btn"
              :disabled="crud.order.orderStatus==='PASS'"
              style="border: none;width: auto;height: auto"
              @click="crud.delRow(scope.$index)"></el-button>
          </template>
        </el-table-column>

      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import crudwareCheck from '@/api/erp/wareCheck'
import CRUD, {presenter, header, form, crud} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";
import {Notification} from "element-ui";
import {productInfo} from "@/api/data";
import JtgTree from "@/components/Tree/JtgTree";
import JtgSelectPlus from "@/components/select/JtgSelectPlus";
import jPrintConfig from '@/components/jPrintConfig/jPrintConfig'
import addBatch from '@/components/addBatch/addBatch'
import {salesDetailKey} from "@/utils/key";
// crud交由presenter持有
const defaultCrud = CRUD({
  title: '盘点单详情',
  sort: 'id,desc',
  name:'wareCheckDetail',
  url: 'api/wareCheckDetail',
  optShow: {
    add: false,
    edit: false,
    del: false,
    download: false,
    upload: false,
    print: false, // 打印
    printDetail: false, // 打印详情
    search: false
  },
  params() {
    const href = location.href.split('/')
    return {
      orderId: href[href.length - 1] == 'null' ? 0 : href[href.length - 1],
    }
  },
  order: {
    id: null,
    busDate: new Date(),
    code: null,
    warehouseId: null,
    checkNum: null,
    userId: null,
    remark: null,
    checkStatus: 'SAVE',
    index: '0'
  },
  crudMethod: {...crudwareCheck}
})
export default {
  name: 'wareCheckDetail',
  components: {
    JtgTree,
    JtgSelectPlus,
    pagination,
    crudOperation,
    rrOperation,
    udOperation,
    MaterialList,
    jPrintConfig,
    addBatch,
  },
  mixins: [presenter(defaultCrud), header(), crud(),salesDetailKey],
  dicts: ['common_yes_or_no'],
  data() {
    return {
      rowIndex: -1,
      columnIndex:0,
      permission: {
        add: ['admin', 'wareCheck:add'],
        edit: ['admin', 'wareCheck:edit'],
        del: ['admin', 'wareCheck:del'],
        enable: ['admin', 'wareCheck:enable'],
        disable: ['admin', 'wareCheck:disable'],
        pass: ['admin', 'wareCheck:pass'],
        reject: ['admin', 'wareCheck:reject'],
        closed: ['admin', 'wareCheck:closed'],
        invalid: ['admin', 'wareCheck:invalid'],
        stop: ['admin', 'wareCheck:stop'],
        recover: ['admin', 'wareCheck:recover'],
        upload: ['admin', 'wareCheck:upload'],
        download: ['admin', 'wareCheck:download'],
        copy: ['admin', 'wareCheck:copy'],
        notice: ['admin', 'wareCheck:notice'],
        isReturn: ['admin', 'wareCheck:isReturn'],
        import: ['admin', 'wareCheck:import'],
        export: ['admin', 'wareCheck:export'],
        checkFinish: ['admin', 'wareCheck:checkFinish'],
        checkAppend: ['admin', 'wareCheck:checkAppend'],
        addOrSub: ['admin', 'wareCheck:addOrSub'],
        goodsMerge: ['admin', 'wareCheck:goodsMerge']
      },
      rules: {
        busDate: [
          {required: true, message: '日期不能为空', trigger: 'blur'}
        ],
        warehouseId: [
          {required: true, message: '仓库不能为空', trigger: 'blur'}
        ],
        userId: [
          {required: true, message: '盘点人员不能为空', trigger: 'blur'}
        ]
      },
      showAddBatchDialog: false,
      id: null,
      summaryData: {},
      addRowData: {
        productCode: null,
        productName: null,
        productId: null,
        category: null,
        productTypeName: null,
        model: null,
        unitName: null,
        existNum: null,
        existBox: null,
        occupyNum: null,
        checkCount: null,
        checkBoxCount: null,
        occupyBox: null,
        profitLossNum: null,
        profitLossBox: null,
        productionDate: null,
        expirationDate: null,
      }
    }
  },
  beforeUpdate() {
    if (this.$route.params.id != 'null') {
      this.id = this.$route.params.id
    }
    // if (this.crud.data.length === 0) {
    //   this.crud.data.push(JSON.parse(JSON.stringify(this.addRowData)))
    // }
  },
  created() {
    if (this.$route.params.id == 'null') {
      if( this.crud.getItemInfo("wareCheckDetail_add")){
        return false
      }
      this.crud.order = {
        id: null,
        busDate: new Date(),
        code: null,
        warehouseId: null,
        checkNum: null,
        userId: null,
        remark: null,
        checkStatus: 'SAVE',
        index: '0'
      }
    }
  },
  
  watch: {},
  methods: {
        // 切换行索引
        switchRowIndex(row) {
      if (this.crud.order.orderStatus !== 'PASS') {
        if (row.index === this.rowIndex) {
          this.rowIndex = -1
          return
        }
        this.rowIndex = row.index
      }
    },
    afterChangeGoods(goods) {
      this.showAddBatchDialog = false
      goods.forEach(good => {
        good.isSelected = true
        goods.warehouseId = 0
        goods.locationId = 0
        goods.storehouseId= 0
        this.crud.data.push(good)
      })
      // this.calcuForm()
    },
    toAddList() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.showAddBatchDialog = true
      })
    },
    // 新增
    toAdd(){
      this.crud.data.push({
        isSelected: true,id: null, orderId: null, goodsId: null, goodsCode: null, goodsName: null, barcode: null,
        boxBarcode: null, helpSign: null, model: null, goodsBrandId: null, goodsBrandCode: null, goodsBrandName: null,
        goodsTypeId: null, goodsTypeCode: null, goodsTypeName: null, goodsTagId: null, goodsTagCode: null,
        goodsTagName: null, taxId: null, taxCode: null, taxName: null, taxRate: null, firstUnitId: null,
        firstUnitCode: null, firstUnitName: null, firstUnitCount: null, effectGoodsCount: null,
        cutOffGoodsCount: null, taxPrice: null, noTaxPrice: null, taxBoxPrice: null, noTaxBoxPrice: null,
        seq: null, remark: null, createUserId: null, createUserCode: null, createUserName: null,
        createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null,
        goodsCount: null, boxNum: null, mainNum: null
      })
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    getValue(e,i){
      console.log('this.crud.data',this.crud.data )
      this.crud.data[i].productName = e
      // let temp = this.crud.data[2]
      // this.crud.data[3] = temp
      this.crud.data.map(item => {
        // item.existId = 0
        // item.existNum = 0
        if(item.existBox === null){
          item.existBox = 0
        }
        if(item.occupyBox === null){
          item.occupyBox = 0
        }
        // item.occupyNum = 0
        // item.paperNum = 0
        // item.profitLossNum = 0

        // item.profitLossBox = 0
        // item.stockTaxPrice = 0
        // item.storehouseId = 0
        // item.storehouseName = 0
      })
    },
    getInput(e,name,i){
      if(this.productList){
        if(e){
          this.productList[i].goodsName = name
          this.productList[i].goodstId= e
        }else{
          this.productList[i].goodsName = ''
          this.productList[i].goodsId= null
        }
      }
    },
    tableRules(index, name, value) {
      if (!value) {
        Notification.error({title: '序号【' + index + '】' + name + '不能为空'})
        return false
      } else return true
    },
    //提交
    submit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        const table_rules = [
          {name: '商品名称', value: 'goodsName'}
        ]
        const result = table_rules.some(({name, value}) => {
          const rules = this.$refs.table.data.some((item, index) => {
            if (!this.tableRules((index + 1), name, item[value])) return true
          })
          if (rules) return true
        })
        if (!result) this.save()
      })
    },
    //保存
    save() {
      let that = this
      that.crud.loadingOpen()
      that.crud.order.detailList = that.crud.data
      crudwareCheck.add(that.crud.order).then(res => {
        that.crud.loadingClose(this.$nextTick)
        if (res.status === 200){
          Notification.success({title: '操作成功'})
          this.$router.replace({ path: '/redirect/ware/wareCheckDetail/'+res.data.id })
        }else {
          Notification.error({title: res.msg})
        }


        // this.crud.afterSave(res.id)
        // that.crud.order.detailList = JSON.stringify(that.crud.data)
        // this.crud.cleanItemInfo('wareCheckDetail_add')
      }).catch(e => {
        that.crud.loadingClose(this.$nextTick)
      })
    },
    /*
    * 追加盘点
    * 盘点完成
    * 盈亏调整
    * */
    setCheck(event) {
      crudwareCheck[event](this.$route.params.id).then(res => {
        Notification.success({title: '操作成功'})
      })
    },
    changeNum(row,type){
      if (type === 'count'){
        const box = Math.trunc(Number(row.goodsCount)/Number(row.boxUnitCount))
        const main = Number(row.goodsCount)%Number(row.boxUnitCount)
        this.$set(row,'boxNum',box)
        this.$set(row,'mainNum',main)
      }else if(type === 'box'){
        const goodsCount = Number(row.boxNum)*Number(row.boxUnitCount) + Number(row.mainNum)
        this.$set(row,'goodsCount',goodsCount)
      }else {
        const goodsCount = Number(row.boxNum)*Number(row.boxUnitCount) + Number(row.mainNum)
        this.$set(row,'goodsCount',goodsCount)
        const box = Math.trunc(Number(row.goodsCount)/Number(row.boxUnitCount))
        const main = Number(row.goodsCount)%Number(row.boxUnitCount)
        this.$set(row,'boxNum',box)
        this.$set(row,'mainNum',main)
      }
      row.paperNum =   Number(row.existNum) - Number(row.pickNum)
      row.paperBoxNum = Math.trunc(Number(row.paperNum)/Number(row.boxUnitCount))
      row.paperMainNum = Number(row.paperNum)%Number(row.boxUnitCount)

      row.profitLossNum = Number(row.goodsCount) - Number(row.paperNum)
      row.profitLossBoxNum = Math.trunc(Number(row.profitLossNum)/Number(row.boxUnitCount))
      row.profitLossMainNum = Number(row.profitLossNum)%Number(row.boxUnitCount)

      this.$forceUpdate()
    },
    changeWarehouseId(e){
      this.crud.order.warehouseId = e.id
      this.crud.order.warehouseName = e.name
    },
    clearWarehouseId(e){
      this.crud.order.warehouseId = 0
      this.crud.order.warehouseName = ''
    },
    goodsMerge(){
      crudwareCheck.goodsMerge({orderId:this.crud.order.id}).then(res=>{
        if (res.status === 200){
          this.$message.success('操作成功')
          this.crud.refresh()
        }
      })
    }
  }
}


</script>
